﻿using System;
using System.Collections.Generic;
using Mono.Cecil.PE;

namespace Mono.Cecil.Metadata
{
	// Token: 0x020000FF RID: 255
	internal sealed class BlobHeapBuffer : HeapBuffer
	{
		// Token: 0x170002BF RID: 703
		// (get) Token: 0x06000A3E RID: 2622 RVA: 0x0002E348 File Offset: 0x0002C548
		public override bool IsEmpty
		{
			get
			{
				return this.length <= 1;
			}
		}

		// Token: 0x06000A3F RID: 2623 RVA: 0x00005AB0 File Offset: 0x00003CB0
		public BlobHeapBuffer() : base(1)
		{
			base.WriteByte(0);
		}

		// Token: 0x06000A40 RID: 2624 RVA: 0x0002E5A0 File Offset: 0x0002C7A0
		public uint GetBlobIndex(ByteBuffer blob)
		{
			uint position;
			bool flag = this.blobs.TryGetValue(blob, out position);
			uint result;
			if (flag)
			{
				result = position;
			}
			else
			{
				position = (uint)this.position;
				this.WriteBlob(blob);
				this.blobs.Add(blob, position);
				result = position;
			}
			return result;
		}

		// Token: 0x06000A41 RID: 2625 RVA: 0x00005AD3 File Offset: 0x00003CD3
		private void WriteBlob(ByteBuffer blob)
		{
			base.WriteCompressedUInt32((uint)blob.length);
			base.WriteBytes(blob);
		}

		// Token: 0x04000424 RID: 1060
		private readonly Dictionary<ByteBuffer, uint> blobs = new Dictionary<ByteBuffer, uint>(new ByteBufferEqualityComparer());
	}
}
